]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
scripting: Convert to ES module and migrate tests
authorEvan Welsh <contact@evanwelsh.com>
Thu, 6 Jul 2023 01:08:09 +0000 (18:08 -0700)
committerEvan Welsh <contact@evanwelsh.com>
Sat, 15 Jul 2023 02:35:56 +0000 (02:35 +0000)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>

.eslintrc.yml
js/ui/main.js
js/ui/scripting.js
tests/shell/basic.js
tests/shell/closeWithActiveWindows.js
tests/shell/core.js
tests/shell/headlessStart.js
tests/shell/hwtest.js

index 16c8ab0947d59891cf7575cdf051a65aa095b3a6..a9bf8e04c1d528af81a68815c3f2f17b75f35a04 100644 (file)
@@ -5,6 +5,7 @@ overrides:
   - files:
       - js/ui/init.js
       - js/ui/environment.js
+      - js/ui/scripting.js
       - js/dbusServices/**
       - js/portalHelper/**
       - subprojects/extensions-app/**
index 34a3b0e78d7e0718f3c0582ed9fa5cf0409219a7..a7d86b570ec07777294ea4fc8e5fe5a9688a06dc 100644 (file)
@@ -44,7 +44,6 @@ const NotificationDaemon = imports.ui.notificationDaemon;
 const WindowAttentionHandler = imports.ui.windowAttentionHandler;
 const Screenshot = imports.ui.screenshot;
 const ScreenShield = imports.ui.screenShield;
-const Scripting = imports.ui.scripting;
 const SessionMode = imports.ui.sessionMode;
 const ShellDBus = imports.ui.shellDBus;
 const ShellMountOperation = imports.ui.shellMountOperation;
@@ -303,9 +302,11 @@ async function _initializeUI() {
         });
     }
 
+    let Scripting;
     let perfModule;
     const {automationScript} = global;
     if (automationScript) {
+        Scripting = await import('./scripting.js');
         perfModule = await import(automationScript.get_uri());
         if (perfModule.init)
             perfModule.init();
index 35373489923e61ddf85d71d8efaa1df5198b4123..fb31bab2757bed5ca533ac1ea57885c6868fa430 100644 (file)
@@ -1,12 +1,9 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported sleep, waitLeisure, createTestWindow, waitTestWindows,
-            destroyTestWindows, defineScriptEvent, scriptEvent,
-            collectStatistics, runPerfScript, disableHelperAutoExit */
 
-const Gio = imports.gi.Gio;
-const GLib = imports.gi.GLib;
-const Meta = imports.gi.Meta;
-const Shell = imports.gi.Shell;
+import Gio from 'gi://Gio';
+import GLib from 'gi://GLib';
+import Meta from 'gi://Meta';
+import Shell from 'gi://Shell';
 
 const Config = imports.misc.config;
 const Main = imports.ui.main;
@@ -41,7 +38,7 @@ const { loadInterfaceXML } = imports.misc.fileUtils;
  * current script for the specified amount of time. Use as
  * 'yield Scripting.sleep(500);'
  */
-function sleep(milliseconds) {
+export function sleep(milliseconds) {
     return new Promise(resolve => {
         let id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, milliseconds, () => {
             resolve();
@@ -59,18 +56,19 @@ function sleep(milliseconds) {
  * current script until the shell is completely idle. Use as
  * 'yield Scripting.waitLeisure();'
  */
-function waitLeisure() {
+export function waitLeisure() {
     return new Promise(resolve => {
         global.run_at_leisure(resolve);
     });
 }
 
 const PerfHelperIface = loadInterfaceXML('org.gnome.Shell.PerfHelper');
-var PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface);
+export const PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface);
 
 let _perfHelper = null;
-/** private */
-async function _getPerfHelper() {
+
+/** @private */
+export async function _getPerfHelper() {
     if (_perfHelper == null) {
         _perfHelper = await PerfHelperProxy.newAsync(
             Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
@@ -80,7 +78,8 @@ async function _getPerfHelper() {
     return _perfHelper;
 }
 
-function _spawnPerfHelper() {
+/** @private */
+export function _spawnPerfHelper() {
     let path = GLib.getenv('GNOME_SHELL_BUILDDIR') || Config.LIBEXECDIR;
     let command = `${path}/gnome-shell-perf-helper`;
     Util.trySpawnCommandLine(command);
@@ -102,7 +101,7 @@ function _spawnPerfHelper() {
  * because of the normal X asynchronous mapping process, to actually wait
  * until the window has been mapped and exposed, use waitTestWindows().
  */
-async function createTestWindow(params) {
+export async function createTestWindow(params) {
     params = Params.parse(params, {
         width: 640,
         height: 480,
@@ -121,12 +120,13 @@ async function createTestWindow(params) {
 
 /**
  * waitTestWindows:
+ *
  * @returns {Promise}
  *
  * Used within an automation script to pause until all windows previously
  * created with createTestWindow have been mapped and exposed.
  */
-async function waitTestWindows() {
+export async function waitTestWindows() {
     let perfHelper = await _getPerfHelper();
     return perfHelper.WaitWindowsAsync().catch(logError);
 }
@@ -141,7 +141,7 @@ async function waitTestWindows() {
  * this doesn't guarantee that Mutter has actually finished the destroy
  * process because of normal X asynchronicity.
  */
-async function destroyTestWindows() {
+export async function destroyTestWindows() {
     let perfHelper = await _getPerfHelper();
     return perfHelper.DestroyWindowsAsync().catch(logError);
 }
@@ -152,7 +152,7 @@ async function destroyTestWindows() {
  * Don't exixt the perf helper after running the script. Instead it will remain
  * running until something else makes it exit, e.g. the Wayland socket closing.
  */
-async function disableHelperAutoExit() {
+export async function disableHelperAutoExit() {
     let perfHelper = await _getPerfHelper();
     perfHelper._autoExit = false;
 }
@@ -166,7 +166,7 @@ async function disableHelperAutoExit() {
  * within the 'script' namespace that is reserved for events defined locally
  * within a performance automation script
  */
-function defineScriptEvent(name, description) {
+export function defineScriptEvent(name, description) {
     Shell.PerfLog.get_default().define_event(`script.${name}`,
                                              description,
                                              "");
@@ -174,12 +174,13 @@ function defineScriptEvent(name, description) {
 
 /**
  * scriptEvent
- * @param {string} name: Name registered with defineScriptEvent()
+ *
+ * @param {string} name Name registered with defineScriptEvent()
  *
  * Convenience function to record a script-local performance event
  * previously defined with defineScriptEvent
  */
-function scriptEvent(name) {
+export function scriptEvent(name) {
     Shell.PerfLog.get_default().event(`script.${name}`);
 }
 
@@ -188,7 +189,7 @@ function scriptEvent(name) {
  *
  * Convenience function to trigger statistics collection
  */
-function collectStatistics() {
+export function collectStatistics() {
     Shell.PerfLog.get_default().collect_statistics();
 }
 
@@ -354,8 +355,8 @@ async function _runPerfScript(scriptModule, outputFile) {
  *
  * After running the script and collecting statistics from the
  * event log, GNOME Shell will exit.
- **/
-function runPerfScript(scriptModule, outputFile) {
+ */
+export function runPerfScript(scriptModule, outputFile) {
     Shell.PerfLog.get_default().set_enabled(true);
     _spawnPerfHelper();
 
index 04c3f87112f2b66b2ba4dcccc72c0908fd0c332f..30f183aa12862f3f29830209877ae6648dffd17a 100644 (file)
@@ -5,7 +5,7 @@ import St from 'gi://St';
 
 const Main = imports.ui.main;
 const MessageTray = imports.ui.messageTray;
-const Scripting = imports.ui.scripting;
+import * as Scripting from 'resource://org/gnome/shell/ui/scripting.js';
 
 // This script tests the most important (basic) functionality of the shell.
 
index a2bec795429ae6a9d979b5fc2e05e8a59217a95f..cee4700956a9b40ac795acfcefc2687d29e82e85 100644 (file)
@@ -4,7 +4,7 @@
 import Clutter from 'gi://Clutter';
 
 const Main = imports.ui.main;
-const Scripting = imports.ui.scripting;
+import * as Scripting from 'resource://org/gnome/shell/ui/scripting.js';
 
 /** Run test. */
 export async function run() {
index 12d9cb060d423f00f86cda4ce526d95b4bee0bf7..593382ac47cd74922cfe86e6847e8c36d5010e3d 100644 (file)
@@ -4,7 +4,7 @@
 import System from 'system';
 
 const Main = imports.ui.main;
-const Scripting = imports.ui.scripting;
+import * as Scripting from 'resource://org/gnome/shell/ui/scripting.js';
 
 // This performance script measure the most important (core) performance
 // metrics for the shell. By looking at the output metrics of this script
index 120d259d07d9e2eb1d22a7dd08723837ae1b4e29..cf9c9436c6ac52d61ff29f7ae4756cb0212caab9 100644 (file)
@@ -6,7 +6,7 @@ import MetaTest from 'gi://MetaTest';
 import Shell from 'gi://Shell';
 
 const Main = imports.ui.main;
-const Scripting = imports.ui.scripting;
+import * as Scripting from 'resource://org/gnome/shell/ui/scripting.js';
 
 // This script tests that the shell handles connecting monitors after startup
 // is properly handled.
index 6e72676149b8a338fbcc57ffc9a1a7e471d75885..e9e0ab074413fbb6c6f378b4af129711e0557539 100644 (file)
@@ -3,7 +3,7 @@ import Clutter from 'gi://Clutter';
 import Gio from 'gi://Gio';
 import Shell from 'gi://Shell';
 const Main = imports.ui.main;
-const Scripting = imports.ui.scripting;
+import * as Scripting from 'resource://org/gnome/shell/ui/scripting.js';
 
 export var METRICS = {
     timeToDesktop: {